import drawChart from './waterChart';
import { maxBy } from 'lodash';
let chartOptsAfter = (chartOpts) => {
  chartOpts.yAxis.forEach(yAxis => {
    delete yAxis.plotLines;
  });
  chartOpts.yAxis[0].plotBands = [
    { /*一到六级*/
      id: 0,
      from: 0.01,
      to: 0.05,
      color: 'rgba(0, 0, 255, 0.6)',
      label: {
        text: '轻微积水',
        align: 'right',
        x: -5,
        style: {
          color: '#9966FF'
        }
      }
    }, { /* 七级*/
      id: 1,
      from: 0.05,
      to: 0.25,
      color: 'rgba(255, 255, 0, 0.6)',
      label: {
        text: '一般积水',
        align: 'right',
        x: -5,
        style: {
          color: '#9966FF'
        }
      }
    }, { /* 八级*/
      idx: 2,
      from: 0.25,
      to: 0.5,
      color: 'rgba(255, 153, 0, 0.6)',
      label: {
        text: '较大积水',
        align: 'right',
        x: -5,
        style: {
          color: '#9966FF'
        }
      }
    }, { /* 九级*/
      idx: 3,
      from: 0.5,
      to: 9999.0,
      color: 'rgba(255, 0, 0, 0.6)',
      label: {
        text: '严重积水',
        align: 'right',
        x: -5,
        style: {
          color: '#9966FF'
        }
      }
    }];
  chartOpts.xAxis.tickInterval = 1000 * 60 * 5;
  let maxVal = maxBy(chartOpts.series[0].data, 'y') || { y: 0 };
  chartOpts.yAxis[0].max = Math.max(maxVal.y, 0.8);
  chartOpts.chart.marginLeft = 40;
  chartOpts.yAxis[0].tickInterval = (chartOpts.yAxis[0].max - chartOpts.yAxis[0].min) / 6;
};

let renderChart = (chartViewer, chartId, waterData, beginTime, endTime) => {
  return drawChart(chartViewer, chartId, waterData, beginTime, endTime, chartOptsAfter);
};

export default renderChart;